package it.univaq.mancoosi.injectors.systemconfiguration.managers;

import it.univaq.mancoosi.injectors.systemconfiguration.managers.ubuntu.UbuntuEnvironmentManager;
import it.univaq.mancoosi.mancoosimm.EmacsPackage;
import it.univaq.mancoosi.mancoosimm.File;
import it.univaq.mancoosi.mancoosimm.MancoosiFactory;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;

public abstract class EmacsManager {
	
	protected static EmacsManager INSTANCE;
	protected MancoosiFactory factory; 
	protected EmacsPackage emacsPackage;
	protected HashMap<String, File> filesMap; 

	public EmacsPackage getEmacsPackage() {
		return emacsPackage;
	}

	protected EmacsManager(){
		this.factory = MancoosiFactory.eINSTANCE;
		emacsPackage = factory.createEmacsPackage(); 
		this.filesMap = new HashMap<String, File>();
	}

	public static EmacsManager getInstance() {
		return INSTANCE;
	}

	public abstract void createEmacsPackageFromSystem();

	public abstract void synchronize() throws IOException;
	
	public abstract Boolean existsFile(String fileLocation);
	
	public void syncFilesMap () {
		Iterator<File> iterator  = null;
		if(UbuntuEnvironmentManager.getInstance().getEnvironment().getEmacspkg() != null){
			int i = UbuntuEnvironmentManager.getInstance().getEnvironment().getEmacspkg().getFiles().size();
			iterator = UbuntuEnvironmentManager.getInstance().getEnvironment().getEmacspkg().getFiles().iterator();
		}
		if(iterator != null){
			while (iterator.hasNext()) {
				File curr = iterator.next();
				this.filesMap.put(curr.getLocation(), curr);
			}
		}
	}

}
